Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

C Programming Interviews Questions


C Language variable and Data Storage...

Q.1 Where in memory are my variables stored?

Variables in memory are stored in different segments based on their type and lifetime:

  1. Global variables: Stored in the Data segment.
  2. Static variables: Also stored in the Data segment.
  3. Local variables: Stored in the Stack segment.
  4. Dynamic variables: Allocated on the Heap segment.

Q.2 Do variables need to be initialized?

Yes, variables need to be initialized to ensure they hold a defined value before they are used. Uninitialized variables can contain garbage values, leading to unpredictable behavior or bugs in the program.

Q.3 What is page thrashing?

Page thrashing is a situation in virtual memory where the CPU spends most of its time swapping pages between RAM and disk, causing a severe slowdown. Imagine constantly having to shuffle papers around to find the one you need to work on - that's thrashing for your computer's memory.

Q.4 What is a const pointer?

A const pointer in C++/C is a pointer declared with const that can't be reassigned to point to a different memory location. Think of it like a fixed address, you can modify the value at that address but you can't move the pointer itself.

Q.5 When should the const modifier be used?

The const modifier should be used when you want to declare a variable whose value will not change throughout its lifetime.

Q.6 Can a variable be both const and volatile?

Yes, a variable can be both const and volatile.

Q.7 When should the volatile modifier be used?

The volatile modifier should be used when you want to indicate that a variable's value can be changed unexpectedly, often by external factors beyond the program's control, such as hardware or other threads.

Q.8 When should the register modifier be used? Does it really help?

The register modifier is deprecated in modern C and C++ standards. It was originally intended to suggest to the compiler to store a variable in a CPU register for faster access. However, modern compilers are generally better at optimizing code, so manually specifying register storage often doesn't provide significant performance benefits.

Q.9 How reliable are floating-point comparisons?

Floating-point comparisons can be unreliable due to precision issues caused by the finite representation of real numbers in binary.

Q.10 How can you determine the maximum value that a numeric variable can hold?

The maximum value that a numeric variable can hold depends on its data type, which can be determined by looking at the range defined for that data type in the language's specification or documentation.

Q.11Are there any problems with performing mathematical operations on different variable types?

Yes, performing mathematical operations on different variable types can lead to implicit type conversions and loss of precision, potentially causing unexpected results or errors in the calculations.

Q.12 What is operator promotion?

Operator promotion is the implicit conversion of operands to a common type before performing an operation, typically to ensure that both operands have the same type to facilitate the operation.

Q.13 When should a type cast be used?

A type cast should be used when you need to explicitly convert a value from one data type to another, typically to ensure compatibility or to force a specific behavior in an expression.

Q.14 When should a type cast not be used?

A type cast should not be used to suppress warnings or errors without addressing the underlying issue causing them. It's also not advisable to use type casts to hide logical errors or to force a type conversion that may lead to loss of data or precision without careful consideration.




Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML 5

Python

java

C++

C

JavaScript

Campus Learning

C

C#

java